{% extends 'index.html' %}
{% block subtitle %}- 个人中心{% endblock %}

<!--head-->
{% block head %}
    <style type="text/css">
    #person_table {
        margin: 40px auto;
        border: 1px #0d8923 solid;
        background-color: #c1ffc6;
        border-radius:10px;
        width:600px;
        height:300px;
    }
    td{
        text-align-all: center;
        margin-left: 40px;
    }
    span{
          margin-left: 20px;
    }
    </style>
    <script type="text/javascript">
     function saveChange(){
         var username = document.getElementById("username").value
         var password = document.getElementById("password").value;
         var address = document.getElementById("address").value;
        var data= {
            data: JSON.stringify({
            "username": username,
            "password": password,
            "address": address,
        }),
        }
        $.ajax({
        url:"/personals/",
        type:"post",
        data:data,
        datatype:"json",
        success:function(data){
            if (data['code'] === 200)
            {
                alert("保存修改成功")
                window.location.href = "{{ url_for('main.personals') }}"
            }
            else if(data['code'] ===402)
                {
                alert("该账号名已被注册，请换一个账号名")
                }
        },
        error:function(error){
            console.log(error)
            alert("出现未知错误")
        }
        })
     }
    </script>
{% endblock %}

{% block content %}
<table id="person_table">
        <caption align="top">
            <p>个人信息</p>
        </caption>
        <tr>
            <td>用户ID:&nbsp;&nbsp;&nbsp;&nbsp;<span><input class="itxt" type="text" placeholder="{{ personals_info_list['UserID'] }}" id="userid" /></span></td>
        </tr>
        <tr>
            <td>用户名:&nbsp;&nbsp;&nbsp;&nbsp;<span><input class="itxt" type="text" value="{{ personals_info_list['UserName'] }}" placeholder="可输入新用户名" id="username" /></span></td>
        </tr>
        <tr>
            <td>修改密码:<span><input class="itxt" type="text" placeholder="可输入新密码" id="password" /></span></td>
        </tr>
        <tr>
            <td>用户地址:<span><input class="itxt" type="text" value="{{ personals_info_list['UserAddress'] }}" placeholder="可输入新用户地址" id="address" /></span></td>
        </tr>
        <tr>
            <td>账户金额:<span><input class="itxt" type="text" placeholder="{{ personals_info_list['UserMoney'] }}" id="money" /></span></td>
        </tr>
        <tr>
            <td><input type="button" class = "input_button" value="保存修改"  id="sub_btn" onclick="saveChange()"></td>
        </tr>
{#        <tr>#}
{#            <td colspan="5" align="center">待发货:</td><span></span>#}
{#        </tr>#}
{#        <tr>#}
{#            <td colspan="5" align="center">待付款:</td><span></span>#}
{#        </tr>#}
    </table>
{% endblock %}